import java.util.*;

public class Process {
	private ArrayList<ICycle> m_cycles;

	// Constructor
	//
	public Process() {
		m_cycles = new ArrayList<ICycle>();
	}

	public String toString() {
		return "\n";
	}

	//
	// Accessors
	//
	public long numCycles() {
		return m_cycles.size();
	}

	public long getNextSetOfCPUCycles() {
		long numberOfCPUCycles = 0;
		boolean firstInstance = false;

		for (ICycle cycle : m_cycles) {
			if (cycle instanceof CPUCycle && !firstInstance) {
				++numberOfCPUCycles;
			} else if (cycle instanceof IOCycle && !firstInstance) {
				firstInstance = true;
			} else {
				break;
			}
		}

		return numberOfCPUCycles;
	}

	public ICycle peekNextCycle() {
		ICycle cycle = null;
		if (numCycles() > 0) {
			cycle = m_cycles.get(0);
		}
		return cycle;
	}

	public boolean isDone() {
		return m_cycles.isEmpty();
	}

	//
	// Mutators
	//

	public void addCycle(ICycle cycle) {
		m_cycles.add(cycle);
	}

	public void consumeCycle() {
		if (numCycles() > 0) {
			m_cycles.remove(0);
		}
	}

	public void execute() {
		consumeCycle();
	}
}
